﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace AdatbazisProjekt
{
    public partial class Userek : Form
    {
       public userStruct s;
        public Userek()
        {
            InitializeComponent();
            s=new userStruct();
            UserDal p=new UserDal();
            s=p.getUserName();
            UserNevCB.DataSource = s.username;
          //  UserRangCB.DataSource = s.userpriv;
        }

        private void addUsrBT_Click(object sender, EventArgs e)
        {
            label3.Visible = true;
            label4.Visible = true;
            label5.Visible = true;
            UserNameTB.Visible = true;
            UserRankTB.Visible = true;
            passwdTB.Visible = true;
            saveUsrBT.Visible = true;
        }

        private void UserNevCB_SelectedIndexChanged(object sender, EventArgs e)
        {
           privLB.Text=s.userpriv[UserNevCB.SelectedIndex];
        }

        private void Userek_Load(object sender, EventArgs e)
        {

        }

        private void SetUsrBT_Click(object sender, EventArgs e)
        {
            newUsrRankTB.Visible = true;
            saveNewUserRank.Visible = true;
            newUsrRankTB.Text = s.userpriv[UserNevCB.SelectedIndex];
        }

        private void saveNewUserRank_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt16(newUsrRankTB.Text) > 3)
            {
                MessageBox.Show("Tul Nagy rank!!(1-3 helyes)");
            }
            else {
                UserDal p = new UserDal();
                p.userUpdate(s.username[UserNevCB.SelectedIndex], newUsrRankTB.Text);
                s = p.getUserName();
                newUsrRankTB.Visible = false;
                saveNewUserRank.Visible = false;

            }
        }

        private void saveUsrBT_Click(object sender, EventArgs e)
        {
            UserDal p = new UserDal();
            p.insertUser(UserNameTB.Text, UserRankTB.Text, passwdTB.Text);
            s = p.getUserName();
            label3.Visible = false;
            label4.Visible = false;
            label5.Visible = false;
            UserNameTB.Visible = false;
            UserRankTB.Visible = false;
            passwdTB.Visible = false;
            saveUsrBT.Visible = false;
            UserNevCB.DataSource = s.username;

        }

        private void deletBT_Click(object sender, EventArgs e)
        {
            UserDal p = new UserDal();
            p.deleteUser(s.username[UserNevCB.SelectedIndex]);
            s = p.getUserName();
            UserNevCB.DataSource = s.username;
           
        }
    }
}
